package com.enjoy.concurrent.ch9;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OrderTest {

    private int a = 0;
    private boolean flag = false;

    private void write() {
        a = 1;
        flag = true;
    }

    private void read() {
        if (flag) {
            a = a + 1;
            log.info("a:{}", a);
            log.info("flag:{}", flag);
        }
    }

    public static void main(String[] args) {
        OrderTest orderTest = new OrderTest();
        new Thread(() -> {
            orderTest.write();
            orderTest.read();
        }, "t1").start();
    }
}
